# -*- coding:utf-8 -*-
# @Project:
# @File:
# @Date:
# @Author:Joe
# @Description:
import re
from selenium.webdriver.common.by import By
from basic_operation import BasicOperation
from time import sleep
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
import json
import allure
from selenium.webdriver.chrome.options import Options
from lxml import etree
from common.log import log

service = Service('C:/Python/chromedriver.exe')
chrome_options = Options()


# chrome_options.add_argument('--ignore-certificate-errors')
# chrome_options.add_argument('--allow-running-insecure-content')
# chrome_options.add_argument('--headless')


class Methods:
    def __init__(self, driver=None):
        if driver:
            self.driver = driver
        else:
            self.driver = webdriver.Chrome(service=service, options=chrome_options)
            self.driver.maximize_window()
            # 设置隐式等待
            self.driver.implicitly_wait(2)
        self.base = BasicOperation(self.driver)

    """登录模块"""

    @allure.step('登录模块-没有该用户、密码错误')
    def login_e(self, url, username_ele, username, pwd_ele, pwd, submit_ele, e_ele, e_text):
        """登录模块-没有该用户、密码错误"""
        with allure.step('访问私有云网站，进入登录页面'):
            self.base.get_url(url)
        with allure.step('输入用户名-error'):
            self.base.input_box(username_ele, username)
        with allure.step('输入密码-error'):
            self.base.input_box(pwd_ele, pwd)
        with allure.step('点击登录按钮'):
            self.base.sel_click(submit_ele)
        with allure.step('获取错误提示'):
            tip = self.base.get_text(e_ele)
        with allure.step('断言：验证错误提示语'):
            assert e_text in tip
        sleep(4)

    @allure.step('登录模块-登录')
    def login(self, url, username_ele, username, pwd_ele, pwd, submit_ele, user_ele, user_text):
        """登录模块-登录"""
        with allure.step('访问私有云网站，进入登录页面'):
            self.base.get_url(url)
        with allure.step('输入用户名'):
            self.base.input_box(username_ele, username)
        with allure.step('输入密码'):
            self.base.input_box(pwd_ele, pwd)
        with allure.step('点击登录按钮'):
            self.base.sel_click(submit_ele)
        with allure.step('获取用户登录信息'):
            if user_ele == ('xpath', ' '):
                user_t = "您好 用户，fmt"
            else:
                user_t = self.base.get_text(user_ele)
        with allure.step('断言：验证用户登录成功状态'):
            assert user_text in user_t

    """通用方法"""

    # @allure.step('跳转模块页面')
    def open_page(self, page_xpath):
        with allure.step('点击模块，跳转到模块页面'):
            self.base.sel_click((By.XPATH, page_xpath))

    # @allure.step('点击打开新标签页面')
    def open_module(self, module_xpath):
        with allure.step('点击模块，跳转到模块页面'):
            self.base.sel_click((By.XPATH, module_xpath))
        with allure.step('锚点切换到新窗口'):
            self.base.switch_to_window()

    # @allure.step('跳转或打开模块页面')
    def open_page_by(self, page_xpath):
        with allure.step('点击模块，跳转到或打开模块页面'):
            is_blank = self.base.get_target((By.XPATH, page_xpath))
            self.base.sel_click((By.XPATH, page_xpath))
            if is_blank:
                self.base.switch_to_window()

    # @allure.step('关闭当前标签页面，切换锚点')
    def close_module(self):
        with allure.step('关闭当前页面'):
            self.base.close_window()
        with allure.step('锚点切换到上一窗口'):
            self.base.switch_to_window()

    # @allure.step('返回上一页')
    def back_page(self):
        with allure.step('返回上一页面'):
            self.base.back_page()
            sleep(1)

    """退出"""

    # @allure.step('退出浏览器')
    def quit(self):
        with allure.step('退出浏览器'):
            self.base.quit()

    """获取导航栏菜单"""

    def get_nav_menu(self, bar_xpath, mode=0):
        with allure.step('获取导航栏菜单列表'):
            bar_list = self.base.get_text_list((By.XPATH, bar_xpath), mode)
            sleep(1)
            return bar_list

    """点击进入菜单"""

    def click_menu(self, the_bar, bar_xpath, menu_text):
        with allure.step('点击导航栏菜单'):
            if the_bar == menu_text:
                the_bar_xpath = bar_xpath + f"[contains(text(), '{menu_text}')]"
                self.base.sel_click(the_bar_xpath)

    """系统首页-顶部按钮"""

    @allure.step('系统首页-顶部按钮-系统手册|收藏夹')
    def top_btn(self, click_xpath, except_xpath, result):
        with allure.step('点击系统首页-顶部系统手册|收藏夹按钮'):
            self.base.sel_click((By.XPATH, click_xpath))
        with allure.step('锚点切换到新窗口'):
            self.base.switch_to_window()
        with allure.step('获取系统手册|收藏夹窗口标题'):
            text = self.base.get_text((By.XPATH, except_xpath))
        with allure.step('关闭系统手册|收藏夹窗口'):
            self.base.close_window()
        sleep(0.2)
        with allure.step('锚点切换到上一窗口'):
            self.base.switch_to_window()
        with allure.step('断言：验证系统手册|收藏夹窗口标题'):
            assert result in text

    """标准法规-标法模块"""

    @allure.step('标法模块-专题按钮')
    def special_title(self, zt_btn_xpath, zt_except_xpath, zt_result):
        with allure.step('点击专题按钮'):
            self.base.sel_click((By.XPATH, zt_btn_xpath))
        sleep(0.2)
        with allure.step('锚点切换到新窗口'):
            self.base.switch_to_window()
        with allure.step('获取专题窗口标题'):
            text = self.base.get_text((By.XPATH, zt_except_xpath))
        with allure.step('关闭专题窗口'):
            self.base.close_window()
        with allure.step('锚点切换到上一窗口'):
            self.base.switch_to_window()
        with allure.step('断言：验证专题窗口标题'):
            assert zt_result in text

    @allure.step('标法模块-标法最新公告信息')
    def latest_news(self, gg_list_ele, gg_content_title_ele):
        with allure.step('获取公告列表'):
            result = self.base.get_text(gg_list_ele, mode=1)
            result = result.strip()
        with allure.step('获取公告列表的信息链接'):
            url = self.base.get_href(gg_list_ele)
        with allure.step('打开新页面访问链接'):
            self.base.open_new_tab(url)
            sleep(0.2)
        with allure.step('锚点切换到新窗口'):
            self.base.switch_to_window()
        with allure.step('获取公告信息详情页标题'):
            text = self.base.get_text(gg_content_title_ele)
            text = text.strip()
        with allure.step('关闭当前页，返回上一级页面'):
            self.base.close_window()
            self.base.switch_to_window()
            sleep(0.2)
        with allure.step('断言：验证公告信息详情页标题'):
            assert text in result

    @allure.step('标法模块-动态列表的更多')
    def dynamic_list_more(self, more_btn, list_name_xpath, list_name):
        try:
            with allure.step('获取更多按钮的链接'):
                more_url = self.base.get_href((By.XPATH, more_btn))
            with allure.step('新标签页打开链接'):
                self.base.open_new_tab(more_url)
                sleep(0.5)
        except Exception:
            print("获取更多按钮的链接失败，点击更多按钮")
            with allure.step('点击更多按钮'):
                self.base.sel_click((By.XPATH, more_btn))
                sleep(0.5)
        with allure.step('锚点切换到新窗口'):
            self.base.switch_to_window()
            sleep(0.2)
        with allure.step('获取列表信息'):
            text = self.base.get_text((By.XPATH, list_name_xpath), mode=1).strip()
        with allure.step('关闭窗口，切换到上一标签页'):
            self.base.close_window()
            self.base.switch_to_window()
        sleep(0.2)
        with allure.step('断言：验证列表名称'):
            assert list_name in text

    @allure.step('标法模块-标法动态列表信息')
    def dynamic_list_info(self, list_xpath, list_1_xpath, content_title_xpath):
        with allure.step('获取列表信息标题'):
            result = self.base.get_text((By.XPATH, list_1_xpath))
        if result:
            with allure.step('获取列表信息链接'):
                url = self.base.get_href((By.XPATH, list_1_xpath))
            with allure.step('新标签页打开链接'):
                self.base.open_new_tab(url)
                sleep(0.5)
            with allure.step('锚点切换到新窗口'):
                self.base.switch_to_window()
            with allure.step('获取详情页标题'):
                text = self.base.get_text((By.XPATH, content_title_xpath))
                text = text.strip()
            with allure.step('关闭窗口，切换到上一标签页'):
                self.base.close_window()
                self.base.switch_to_window()
            sleep(0.2)
            with allure.step('断言：验证详情页标题和列表标题'):
                assert text in result
        else:
            with allure.step('尝试获取“无数据”提示语'):
                no_data = self.base.get_text((By.XPATH, list_xpath), mode=1)
            if "无数据" in no_data:
                with allure.step('该模块无数据，记录日志'):
                    log.info("该模块无数据")

    """标准法规-专题"""

    @allure.step('专题详情')
    def special_t_content(self, title_xpath, title2_xpath):
        with allure.step('获取专题名称'):
            title = self.base.get_text((By.XPATH, title_xpath), mode=1)
        with allure.step('点击专题名称打开专题详情'):
            self.base.sel_click((By.XPATH, title_xpath))
        with allure.step('切换到专题详情页新窗口'):
            self.base.switch_to_window()
        with allure.step('获取详情页专题名称'):
            title2 = self.base.get_text((By.XPATH, title2_xpath), mode=1)
        with allure.step('关闭窗口，切换到上一标签页'):
            self.base.close_window()
            self.base.switch_to_window()
        with allure.step('断言：验证专题名称和详情页专题名称'):
            assert title == title2

    @allure.step('专题详情页-搜索')
    def special_content_search(self, special_title_xpath, keyword_box, zt_keyword, time_s_valve, time_select, s_date_x,
                               s_date, e_date_x, e_date, search_button, country_law_title, country_date, d_s, d_e):
        with allure.step('点击专题名称打开专题详情'):
            self.base.sel_click((By.XPATH, special_title_xpath))
            sleep(0.2)
        with allure.step('切换到专题详情页新窗口'):
            self.base.switch_to_window()
        # 传搜索条件搜索
        with allure.step('输入搜索条件-标题关键词'):
            self.base.input_box((By.XPATH, keyword_box), zt_keyword)
        with allure.step('选择日期类型'):
            self.base.select_box((By.XPATH, time_select), time_s_valve)
        with allure.step('输入开始日期、结束日期'):
            self.base.input_box((By.XPATH, s_date_x), s_date)
            self.base.input_box((By.XPATH, e_date_x), e_date)
        with allure.step('点击搜索'):
            self.base.sel_click((By.XPATH, search_button))
            sleep(0.2)
        with allure.step('获取国家和地方法规列表的标题和日期'):
            country_title = self.base.get_text((By.XPATH, country_law_title), mode=1)
            country_title = re.sub(r'\s+', '', country_title)
            country_date = self.base.get_text((By.XPATH, country_date), mode=1)
        with allure.step('关闭窗口，切换到上一标签页'):
            self.base.close_window()
            self.base.switch_to_window()
        with allure.step('断言：搜索结果包含搜索关键词，日期在搜索日期范围内'):
            assert zt_keyword in country_title
            country_date = int(country_date.replace('-', ''))
            assert int(d_s) <= country_date <= int(d_e)

    @allure.step('专题详情页-法规详情')
    def special_content_content(self, special_title_xpath, law_title, content_title):
        with allure.step('点击专题名称打开专题详情'):
            self.base.sel_click((By.XPATH, special_title_xpath))
            sleep(0.2)
        with allure.step('切换到专题详情页新窗口'):
            self.base.switch_to_window()
        with allure.step('获取国家法规列表的标题'):
            list_law_title = self.base.get_text((By.XPATH, law_title), mode=1)
            list_law_title = re.sub(r'\s+', '', list_law_title)
        with allure.step('点击法规列表的法规名称打开法规详情页'):
            self.base.sel_click((By.XPATH, law_title))
            sleep(0.2)
        with allure.step('切换到法规详情页新窗口'):
            self.base.switch_to_window()
        with allure.step('获取法规详情页的法规名称'):
            content_law_title = self.base.get_text((By.XPATH, content_title), mode=1)
            content_law_title = re.sub(r'\s+', '', content_law_title)
        with allure.step('关闭法规详情窗口，切换到上一标签页'):
            self.base.close_window()
            self.base.switch_to_window()
        with allure.step('关闭专题详情窗口，切换到上一标签页'):
            self.base.close_window()
            self.base.switch_to_window()
        with allure.step('断言：法规详情页的法规名称等于专题详情法规列表的法规名称'):
            assert list_law_title == content_law_title

    """标准法规-法律法规-高级搜索"""

    @allure.step('法律法规-高级搜索-法律法规搜索框')
    def search_input(self, input_xpath, input_value, search_xpath, first_xpath, result_xpath, pop_close_btn, law_xpath):
        with allure.step('输入搜索内容'):
            self.base.input_box((By.XPATH, input_xpath), input_value)
        with allure.step('点击搜索'):
            self.base.sel_click((By.XPATH, search_xpath))
            sleep(0.2)
        # 弹窗详情
        with allure.step('点击打开内容弹窗'):
            self.base.sel_click((By.XPATH, first_xpath))
            self.base.switch_to_frame('layui-layer-iframe1')
        with allure.step('获取弹窗内容'):
            content_text = self.base.get_text((By.XPATH, result_xpath), mode=1)
            self.base.switch_to_default_content()
        # 关闭弹窗
        with allure.step('关闭弹窗'):
            self.base.sel_click((By.XPATH, pop_close_btn))
        with allure.step('点击返回模块首页'):
            self.base.sel_click((By.XPATH, law_xpath))
            sleep(0.2)
        with allure.step('断言：弹窗内容包含搜索关键词'):
            assert input_value in content_text

    @allure.step('法律法规-高级搜索-搜索框无数据')
    def search_none(self, input_xpath, input_value, search_xpath, result_xpath, law_xpath):
        with allure.step('输入搜索内容123456789'):
            self.base.input_box((By.XPATH, input_xpath), input_value)
        with allure.step('点击搜索'):
            self.base.sel_click((By.XPATH, search_xpath))
            sleep(0.2)
        with allure.step('获取搜索结果内容'):
            test = self.base.get_text((By.XPATH, result_xpath), mode=1)
        # print(test)
        with allure.step('点击返回模块首页'):
            self.base.sel_click((By.XPATH, law_xpath))
            sleep(0.2)
        with allure.step('断言：搜索结果为空'):
            assert test is None

    @allure.story('法律法规-高级搜索-普通检索')
    def advanced_search(self, advsrc_button_xpath, reset_xpath, scope_xpath, adv_input_xpath, adv_input_value,
                        search_xpath, first_xpath, result_xpath, pop_close_xpath, law_xpath):
        with allure.step('点击高级检索'):
            self.base.sel_click((By.XPATH, advsrc_button_xpath))
        with allure.step('重置搜索条件'):
            self.base.sel_click((By.XPATH, reset_xpath))
        with allure.step('选择搜索范围-法律法规'):
            self.base.is_selected((By.XPATH, scope_xpath))
        with allure.step('输入搜索内容'):
            self.base.input_box((By.XPATH, adv_input_xpath), adv_input_value)
        with allure.step('点击搜索'):
            self.base.sel_click((By.XPATH, search_xpath))
        with allure.step('点击打开内容弹窗'):
            self.base.sel_click((By.XPATH, first_xpath))
            self.base.switch_to_frame('layui-layer-iframe1')
        with allure.step('获取弹窗内容'):
            content_text = self.base.get_text((By.XPATH, result_xpath), mode=1)
            self.base.switch_to_default_content()
        with allure.step('关闭弹窗'):
            self.base.sel_click((By.XPATH, pop_close_xpath))
        with allure.step('点击返回模块首页'):
            self.base.sel_click((By.XPATH, law_xpath))
            sleep(0.2)
        with allure.step('断言：弹窗内容包含搜索关键词'):
            assert adv_input_value in content_text

    @allure.step('法律法规-高级搜索-添加、删除关键词')
    def advanced_search_keys(self, advsrc_button_xpath, add_xpath, add_xpath2, delete_xpath, delete_xpath2, close_xpath,
                             law_xpath):
        with allure.step('点击高级检索'):
            self.base.sel_click((By.XPATH, advsrc_button_xpath))
        with allure.step('添加关键词框'):
            self.base.sel_click((By.XPATH, add_xpath))
        with allure.step('获取此时添加按钮的标识'):
            add_value = self.base.get_value((By.XPATH, add_xpath2))
        with allure.step('删除关键词框'):
            self.base.sel_click((By.XPATH, delete_xpath))
        with allure.step('获取此时删除按钮的标识'):
            delete_value = self.base.get_value((By.XPATH, delete_xpath2))
        with allure.step('点击关闭弹窗'):
            self.base.sel_click((By.XPATH, close_xpath))
        with allure.step('点击返回模块首页'):
            self.base.sel_click((By.XPATH, law_xpath))
            sleep(0.2)
        with allure.step('断言：添加、删除按钮文字'):
            assert add_value == "添 加"
            assert delete_value == "删 除"

    @allure.story('法律法规-高级搜索-高级检索')
    def advanced_search2(self, advsrc_button_xpath, advanced_xpath, adv_reset_xpath, scope_xpath, key_xpath, keyword,
                         search_button, first_xpath, result_xpath, law_xpath,
                         kw_xpath="//div[@id='selectator_select4']/ul//div[contains(text(), '全国人民代表大会')]"):
        with allure.step('点击高级检索'):
            self.base.sel_click((By.XPATH, advsrc_button_xpath))
        with allure.step('点击高级检索-高级检索'):
            self.base.sel_click((By.XPATH, advanced_xpath))
        with allure.step('重置搜索条件'):
            self.base.sel_click((By.XPATH, adv_reset_xpath))
        with allure.step('设置搜索条件'):
            self.base.sel_click((By.XPATH, scope_xpath))
            self.base.input_box((By.XPATH, key_xpath), keyword)
            if keyword not in ["食品安全法", "电子商务法"]:
                self.base.sel_click((By.XPATH, kw_xpath))
        with allure.step('点击搜索'):
            self.base.sel_click((By.XPATH, search_button))
        with allure.step('点击打开内容弹窗，获取弹窗内容'):
            self.base.sel_click((By.XPATH, first_xpath))
            self.base.switch_to_frame('layui-layer-iframe1')
            content_text = self.base.get_text((By.XPATH, result_xpath), mode=1)
            self.base.switch_to_default_content()
        # 页面还原
        with allure.step('点击返回模块首页'):
            self.base.sel_click((By.XPATH, law_xpath))
            sleep(0.5)
        with allure.step('断言：弹窗内容包含搜索关键词'):
            assert keyword in content_text

    @allure.step('法律法规-高级搜索-检索式')
    def advanced_search3(self, advsrc_button_xpath, src_kw_xpath, jss_reset_xpath, scope_xpath3, input_kw_xpath,
                         keywords, search_xpath, result_xpath, law_xpath, src_k1="水产品", src_k2="通知"):
        with allure.step('点击高级检索-检索式'):
            self.base.sel_click((By.XPATH, advsrc_button_xpath))
            self.base.sel_click((By.XPATH, src_kw_xpath))
        with allure.step('重置搜索条件'):
            self.base.sel_click((By.XPATH, jss_reset_xpath))
        with allure.step('选择搜索项'):
            self.base.is_selected((By.XPATH, scope_xpath3))
        with allure.step('输入检索式内容'):
            self.base.input_box((By.XPATH, input_kw_xpath), keywords)
        with allure.step('点击搜索'):
            self.base.sel_click((By.XPATH, search_xpath))
            sleep(2)
        with allure.step('验证结果'):
            result_text = self.base.get_text((By.XPATH, result_xpath), mode=1).strip()
        with allure.step('点击返回模块首页'):
            self.base.sel_click((By.XPATH, law_xpath))
            sleep(2)
        with allure.step('断言：搜索结果包含检索式内容'):
            assert src_k1 in result_text and src_k2 in result_text

    """标准法规-法律法规"""

    @allure.step('法律法规-法律法规详情')
    def table_message(self, message_xpath, title_xpath):
        with allure.step('获取列表数据文本'):
            message_title = self.base.get_text((By.XPATH, message_xpath)).strip()
        with allure.step('点击列表数据'):
            self.base.sel_click((By.XPATH, message_xpath))
            sleep(0.2)
            self.base.switch_to_window()
        with allure.step('获取详情页内容'):
            detail_title = self.base.get_text((By.XPATH, title_xpath)).strip()
        with allure.step('关闭详情页'):
            self.base.close_window()
            self.base.switch_to_window()
        with allure.step('断言：详情页内容包含列表数据内容'):
            assert detail_title == message_title

    @allure.step('法律法规-法规预览')
    def table_preview(self, message_xpath, preview_xpath, title_xpath, close_xpath):
        with allure.step('获取列表数据文本'):
            message_title = self.base.get_text((By.XPATH, message_xpath))
            # 去掉字符空白
            if message_title:
                message_title = re.sub(r'\s', '', message_title)
        with allure.step('点击列表数据预览打开预览'):
            self.base.sel_click((By.XPATH, preview_xpath))
            sleep(0.2)
        self.base.switch_to_frame('layui-layer-iframe1')
        with allure.step('获取预览页内容'):
            detail_title = self.base.get_text((By.XPATH, title_xpath))
            if detail_title:
                detail_title = re.sub(r'\s', '', detail_title)
        self.base.switch_to_default_content()
        with allure.step('点击关闭弹窗'):
            self.base.sel_click((By.XPATH, close_xpath))
        with allure.step('断言：预览页内容包含列表数据内容'):
            assert detail_title == message_title

    @allure.step('法律法规-列表分类名称')
    def law_table_category(self, category_xpath, cate_t_l_xpath):
        with allure.step('获取列表分类名称'):
            message_category = self.base.get_text((By.XPATH, category_xpath))
            # 去掉字符空白
            if message_category:
                message_title = re.sub(r'\s', '', message_category)
        with allure.step('点击分类'):
            self.base.sel_click((By.XPATH, category_xpath))
            sleep(0.2)
            self.base.switch_to_window()
        with allure.step('获取文本内容'):
            tr_texts = self.base.get_text_list((By.XPATH, cate_t_l_xpath), mode=1)
        with allure.step('关闭详情页，返回模块首页'):
            self.base.close_window()
            self.base.switch_to_window()
        with allure.step('遍历，断言：列表分类名称包含列表数据内容'):
            for tr_text in tr_texts:
                tr_text = re.sub(r'\s', '', tr_text)
                assert tr_text == message_title

    @allure.step('法律法规-法律法规换页详情')
    def table2_message(self, page_two, message_xpath, title_xpath, law_xpath):
        # 切换第二页
        with allure.step('切换第二页'):
            self.base.sel_click((By.XPATH, page_two))
            sleep(0.2)
        with allure.step('获取列表数据文本'):
            message_title = self.base.get_text((By.XPATH, message_xpath))
            # 去掉字符空白
            if message_title:
                message_title = re.sub(r'\s', '', message_title)
        with allure.step('点击列表数据'):
            self.base.sel_click((By.XPATH, message_xpath))
            sleep(0.2)
            self.base.switch_to_window()
        with allure.step('获取详情页内容'):
            detail_title = self.base.get_text((By.XPATH, title_xpath))
            if detail_title:
                detail_title = re.sub(r'\s', '', detail_title)
        with allure.step('关闭详情页'):
            self.base.close_window()
            self.base.switch_to_window()
        with allure.step('返回模块首页'):
            self.base.sel_click((By.XPATH, law_xpath))
        with allure.step('断言：详情页内容包含列表数据内容'):
            assert detail_title == message_title

    @allure.step('法律法规-标法分类')
    def laws_category(self, cate_xzfg_xpath, cate_text_xpath, law_xpath, cate_name_t):
        # 点击分类“行政法规”
        with allure.step('点击分类-行政法规'):
            self.base.sel_click((By.XPATH, cate_xzfg_xpath))
        # 获取文本，验证
        with allure.step('获取文本'):
            category_text = self.base.get_text((By.XPATH, cate_text_xpath))
            if category_text:
                category_text = re.sub(r'\s', '', category_text)
        with allure.step('返回模块首页'):
            self.base.sel_click((By.XPATH, law_xpath))
        with allure.step('断言：验证分类名称'):
            assert category_text == cate_name_t

    """标准法规-标准"""

    @allure.story('标准-标准详情')
    def bz_table_message(self, message_xpath, title_xpath):
        with allure.step('获取列表数据文本'):
            message_title = self.base.get_text((By.XPATH, message_xpath))
            # 去掉字符空白
            if message_title:
                message_title = re.sub(r'\s', '', message_title)
        with allure.step('点击列表数据'):
            self.base.sel_click((By.XPATH, message_xpath))
            sleep(0.2)
            self.base.switch_to_window()
        with allure.step('获取详情页内容'):
            detail_title = self.base.get_text((By.XPATH, title_xpath))
            if detail_title:
                detail_title = re.sub(r'\s', '', detail_title)
        with allure.step('关闭详情页'):
            self.base.close_window()
            self.base.switch_to_window()
        with allure.step('断言：详情页内容包含列表数据内容'):
            assert detail_title == message_title

    """标准法规-标准查新"""

    @allure.step('标准查新-批量录入')
    def batch_input(self, input_xpath, input_text, nextstep_xpath, result1_xpath, previous_xpath, start_xpath,
                    result2_xpath, bzcx_xpath):
        with allure.step('输入内容搜索'):
            self.base.input_box((By.XPATH, input_xpath), input_text)
            self.base.sel_click((By.XPATH, nextstep_xpath))
            sleep(0.2)
        # 获取查新结果一
        with allure.step('获取查新结果一'):
            result1_text_list = self.base.get_text_list((By.XPATH, result1_xpath), mode=1)
        with allure.step('点击上一步'):
            self.base.sel_click((By.XPATH, previous_xpath))
        with allure.step('点击下一步'):
            self.base.sel_click((By.XPATH, nextstep_xpath))
            sleep(0.2)
        with allure.step('点击开始查新'):
            self.base.sel_click((By.XPATH, start_xpath))
        # 获取查新结果二
        with allure.step('获取查新结果二'):
            result2_text_list = self.base.get_text_list((By.XPATH, result2_xpath), mode=1)
        # 还原页面
        with allure.step('还原页面'):
            self.base.sel_click((By.XPATH, bzcx_xpath))
            sleep(0.2)
        # 断言
        with allure.step('断言：查新结果包含输入内容'):
            for result1_text in result1_text_list:
                assert result1_text in input_text
            for result2_text in result2_text_list:
                assert result2_text in input_text

    @allure.step('标准查新-导入模板下载')
    def template_import(self, in_model_xpath, download_xpath, bzcx_xpath):
        with allure.step('点击导入模板模块'):
            self.base.sel_click((By.XPATH, in_model_xpath))
            sleep(0.2)
        with allure.step('获取下载模板链接'):
            download_url = self.base.get_href((By.XPATH, download_xpath))
            sleep(0.2)
        # 还原
        with allure.step('还原页面'):
            self.base.sel_click((By.XPATH, bzcx_xpath))
        with allure.step('断言：链接不为空'):
            assert download_url is not None

    @allure.step('标准查新-更新提醒')
    def update_remind(self, upd_model_xpath, number_xpath, upd_result_xpath, bzcx_xpath):
        with allure.step('获取更新提醒数字'):
            number = self.base.get_text((By.XPATH, number_xpath))
        if number is not None:
            with allure.step('点击更新提醒模块'):
                self.base.sel_click((By.XPATH, upd_model_xpath))
                sleep(0.2)
            with allure.step('获取更新的信息文本'):
                text = self.base.get_text((By.XPATH, upd_result_xpath))
            with allure.step('还原页面'):
                self.base.sel_click((By.XPATH, bzcx_xpath))
            with allure.step('断言：更新提醒信息不为空'):
                assert text is not None
        else:
            log.info('没有更新提醒数据')

    """标准法规-统计模块"""

    @allure.step('统计模块-统计页信息')
    def statistics_index(self, tongji_xpath, law_xpath, standard_xpath, draft_xpath, notification_xpath):
        with allure.step('点击统计模块'):
            self.base.sel_click((By.XPATH, tongji_xpath))
            sleep(1)
        with allure.step('获取统计页信息'):
            law_text = self.base.get_text((By.XPATH, law_xpath), mode=1)
            standard_text = self.base.get_text((By.XPATH, standard_xpath), mode=1)
            draft_text = self.base.get_text((By.XPATH, draft_xpath), mode=1)
            notification_text = self.base.get_text((By.XPATH, notification_xpath), mode=1)
        with allure.step('断言：验证统计页信息字段'):
            assert law_text == "法律法规 统计"
            assert standard_text == "标准 统计"
            assert draft_text == "法规草案 统计"
            assert notification_text == "标准通报 统计"

    @allure.step('统计模块-统计搜索')
    def statistics_search(self, tongji_xpath, law_n_xpath, standard_n_xpath, draft_n_xpath, notification_n_xpath,
                          search_xpath, search_button, law, standard, draft, notification, keyword_xpath, keyword):
        # 获取初始数量
        with allure.step('获取初始数量'):
            law1 = int(self.base.get_text((By.XPATH, law_n_xpath), mode=1))
            standard1 = int(self.base.get_text((By.XPATH, standard_n_xpath), mode=1))
            draft1 = int(self.base.get_text((By.XPATH, draft_n_xpath), mode=1))
            notification1 = int(self.base.get_text((By.XPATH, notification_n_xpath), mode=1))
        # 点击高级搜索
        with allure.step('点击高级搜索'):
            self.base.sel_click((By.XPATH, search_xpath))
        # 判断并选择四个选项
        with allure.step('判断并选择四个选项'):
            self.base.is_selected((By.XPATH, law))
            self.base.is_selected((By.XPATH, standard))
            self.base.is_selected((By.XPATH, draft))
            self.base.is_selected((By.XPATH, notification))
            sleep(0.5)
        # 输入关键词“食品安全”
        with allure.step('输入关键词“食品安全”'):
            self.base.input_box((By.XPATH, keyword_xpath), keyword)
            sleep(0.5)
        # 点击搜索
        with allure.step('点击搜索'):
            self.base.sel_click((By.XPATH, search_button))
            sleep(1)
        # 获取搜索结果数量
        with allure.step('获取搜索结果数量'):
            law2 = int(self.base.get_text((By.XPATH, law_n_xpath), mode=1))
            standard2 = int(self.base.get_text((By.XPATH, standard_n_xpath), mode=1))
            draft2 = int(self.base.get_text((By.XPATH, draft_n_xpath), mode=1))
            notification2 = int(self.base.get_text((By.XPATH, notification_n_xpath), mode=1))
        # 还原
        with allure.step('还原页面'):
            self.base.sel_click((By.XPATH, tongji_xpath))
        with allure.step('断言：搜索结果数量大于等于初始数量'):
            assert law1 >= law2 and standard1 >= standard2 and draft1 >= draft2 and notification1 >= notification2

    """在线小数据库"""

    """小数据库-获得我国检验检疫准入的新鲜水果种类及输出国家名录"""

    @allure.step('在线小数据库-获得我国检验检疫准入的新鲜水果种类及输出国家名录-数据库简介')
    def db_introduction(self, summary_btn, summary_text, close_btn, db_text):
        # 验证数据库简介内容
        with allure.step('点击数据库简介'):
            self.base.sel_click((By.XPATH, summary_btn))
        with allure.step('获取数据库简介文本'):
            text = self.base.get_text((By.XPATH, summary_text), mode=1)
            if text:
                text = re.sub('[^\u4e00-\u9fa5]+', '', text)
        with allure.step('点击还原页面'):
            self.base.sel_click((By.XPATH, close_btn))
        with allure.step('断言：验证数据库简介内容'):
            assert db_text in text

    @allure.step('在线小数据库-新鲜水果-国家/地区搜索')
    def search_state(self, state_search, taiwan_xpath, canada_xpath, search_button, table_states, reset_button,
                     state_n1, state_n2):
        with allure.step('点击国家/地区'):
            self.base.sel_click((By.XPATH, state_search))
        # 选择搜索项
        with allure.step('选择搜索项'):
            self.base.sel_click((By.XPATH, taiwan_xpath))
            self.base.sel_click((By.XPATH, canada_xpath))
        # 点击搜索
        with allure.step('点击搜索'):
            self.base.sel_click((By.XPATH, search_button))
        with allure.step('获取搜索结果列表'):
            text_list = self.base.get_text_list((By.XPATH, table_states), mode=1)
        # 页面还原
        with allure.step('点击还原页面'):
            self.base.sel_click((By.XPATH, reset_button))
        with allure.step('断言：搜索结果列表包含“台湾”和“加拿大”'):
            assert state_n1 in text_list and state_n2 in text_list

    @allure.step('在线小数据库-新鲜水果-水果种类搜索')
    def search_fruits(self, fruits_search, search_button, table_fruits, reset_button):
        # 搜索蓝莓
        with allure.step('输入框搜索'):
            self.base.input_box((By.XPATH, fruits_search), "蓝莓")
            # 点击搜索
            self.base.sel_click((By.XPATH, search_button))
        with allure.step('获取搜索结果列表'):
            text_list_zh = self.base.get_text_list((By.XPATH, table_fruits), mode=1)
        # 页面还原
        with allure.step('点击还原页面'):
            self.base.sel_click((By.XPATH, reset_button))
        # 搜索Blueberry
        with allure.step('输入框搜索-英文'):
            self.base.input_box((By.XPATH, fruits_search), "Blueberry")
            # 点击搜索
            self.base.sel_click((By.XPATH, search_button))
        with allure.step('获取搜索结果列表'):
            text_list_en = self.base.get_text_list((By.XPATH, table_fruits), mode=1)
        # 页面还原
        with allure.step('点击还原页面'):
            self.base.sel_click((By.XPATH, reset_button))
        with allure.step('断言：搜索结果列表包含“蓝莓”和“Blueberry”'):
            for text_zh in text_list_zh:
                assert "蓝莓" in text_zh
            for text_en in text_list_en:
                assert "Blueberry" in text_en

    """小数据库-禁止从动物疫病流行国家地区输入的动物及其产品"""

    # 部分功能同新鲜水果

    @allure.step('在线小数据库-输入框搜索，列表验证关键词')
    def input_box_search(self, src_input_xpath, input_text, search_button, src_list, reset_button):
        """输入框搜索，列表验证关键词"""
        with allure.step('输入框搜索'):
            self.base.input_box((By.XPATH, src_input_xpath), input_text)
            sleep(1)
            self.base.sel_click((By.XPATH, search_button))
            sleep(1)
        with allure.step('获取搜索结果列表'):
            text_list = self.base.get_text_list((By.XPATH, src_list))
        with allure.step('点击还原页面'):
            self.base.sel_click((By.XPATH, reset_button))
        with allure.step('断言：搜索结果列表包含输入框文本'):
            for text in text_list:
                assert input_text in text

    """小数据库-非食用物质和易滥用的食品添加剂查询数据库"""

    @allure.step('在线小数据库-非食用物质和易滥用的食品添加剂查询数据库-非食用物质列表下拉筛选(分类、名称、食品类别)')
    def notfood_list_filter(self, select_xpath, select_text, filter_list, reset_button):
        # 下拉筛选
        with allure.step('下拉筛选'):
            self.base.sel_click((By.XPATH, select_xpath))
            self.base.sel_click((By.XPATH, f'//option[text()="{select_text}"]'))
            sleep(3)
        with allure.step('获取结果列表'):
            text_list = self.base.get_text_list((By.XPATH, filter_list))
        with allure.step('点击还原页面'):
            self.base.sel_click((By.XPATH, reset_button))
        with allure.step('断言：搜索结果列表包含下拉筛选文本'):
            for text in text_list:
                assert select_text in text
        # 所有test_文件中都要修改
        # if select_text == '辣椒粉':
        #     self.base.close_window()
        #     self.base.switch_to_window()

    """小数据库-食品行业专业术语词典库（试用）"""

    @allure.step('在线小数据库-食品行业专业术语词典库（试用）-词典热词搜索')
    def dictionary_hotword(self, select_xpath, hw_result_list, reset_button):
        # 搜索
        with allure.step('点击热词搜索'):
            self.base.sel_click((By.XPATH, select_xpath))
        with allure.step('获取热词'):
            select_word = self.base.get_text((By.XPATH, select_xpath))
        with allure.step('获取搜索结果列表'):
            text_list = self.base.get_text_list((By.XPATH, hw_result_list))
        with allure.step('点击还原页面'):
            self.base.sel_click((By.XPATH, reset_button))
        with allure.step('断言：搜索结果列表包含热词'):
            for text in text_list:
                assert select_word in text

    @allure.step('在线小数据库-食品行业专业术语词典库（试用）-查看详情')
    def dictionary_detail(self, list_name, detail_button, detail_name):
        # 查看详情
        with allure.step('获取列表文本'):
            list_text = self.base.get_text((By.XPATH, list_name))
        with allure.step('点击查看详情'):
            self.base.sel_click((By.XPATH, detail_button))
            self.base.switch_to_window()
        with allure.step('获取详情文本'):
            detail_text = self.base.get_text((By.XPATH, detail_name))
        with allure.step('关闭详情返回模块首页'):
            self.base.close_window()
            self.base.switch_to_window()
        with allure.step('断言：列表文本等于详情文本'):
            assert list_text == detail_text

    """小数据库-GB 14880-2012 食品营养强化剂使用标准"""

    @allure.step('在线小数据库-GB 14880-2012 食品营养强化剂使用标准-首页左侧分类')
    def nutrition_category(self, list_category, result_category, index_page):
        with allure.step('获取列表的文本列表'):
            text_list = self.base.get_text((By.XPATH, list_category))
        with allure.step('点击左侧分类'):
            self.base.sel_click((By.XPATH, list_category))
        with allure.step('获取结果列表的文本列表'):
            result_text = self.base.get_text((By.XPATH, result_category))
        with allure.step('点击返回首页'):
            self.base.sel_click((By.XPATH, index_page))
        with allure.step('断言：列表文本等于结果列表文本'):
            assert text_list == result_text

    @allure.step('在线小数据库-GB 14880-2012 食品营养强化剂使用标准-食品分类详情页')
    def nutrition_category_content(self, category_xpath, page_category, content_text, index_page):
        with allure.step('点击分类模块'):
            self.base.sel_click((By.XPATH, category_xpath))
        with allure.step('获取分类文本'):
            category_text = self.base.get_text((By.XPATH, page_category))
        with allure.step('点击分类'):
            self.base.sel_click((By.XPATH, page_category))
        with allure.step('获取详情页文本'):
            content_t = self.base.get_text((By.XPATH, content_text))
        with allure.step('点击返回首页'):
            self.base.sel_click((By.XPATH, index_page))
        with allure.step('断言：分类文本等于详情页文本'):
            assert category_text in content_t

    @allure.step('在线小数据库-GB 14880-2012 食品营养强化剂使用标准-查询详情页')
    def nutrition_detail(self, nutrition_xpath, page_search_xpath, search_text, search_button, src_results_xpath,
                         content_text, index_page):
        with allure.step('点击查询分类'):
            self.base.sel_click((By.XPATH, nutrition_xpath))
        with allure.step('输入查询文本'):
            self.base.input_box((By.XPATH, page_search_xpath), search_text)
        with allure.step('点击搜索按钮'):
            self.base.sel_click((By.XPATH, search_button))
        with allure.step('获取搜索结果列表'):
            n_texts = self.base.get_text_list((By.XPATH, src_results_xpath))
        with allure.step('点击搜索结果列表的项目名'):
            self.base.sel_click((By.XPATH, src_results_xpath))
        with allure.step('获取详情页文本'):
            n_name = self.base.get_text((By.XPATH, content_text))
        with allure.step('点击返回首页'):
            self.base.sel_click((By.XPATH, index_page))
        with allure.step('断言：搜索结果列表包含查询文本'):
            for n_text in n_texts:
                assert search_text in n_text
            assert n_name in n_texts

    # 营养强化剂-系统查询——调用input_box_search

    """小数据库-GB 31650-2019动物性食品中兽药残留限量查询"""

    @allure.step('在线小数据库-兽药残留-动物种类详情页')
    def veterinary_drugs_category_content(self, category_xpath, page_category, content_text, index_page):
        with allure.step('点击分类模块'):
            self.base.sel_click((By.XPATH, category_xpath))
        with allure.step('获取分类文本'):
            category_text = self.base.get_text((By.XPATH, page_category))
        with allure.step('点击分类'):
            self.base.sel_click((By.XPATH, page_category))
            self.base.switch_to_window()
        with allure.step('获取详情页文本'):
            content_t = self.base.get_text((By.XPATH, content_text))
        with allure.step('关闭分类页面，点击返回首页'):
            self.base.close_window()
            self.base.switch_to_window()
            self.base.sel_click((By.XPATH, index_page))
        with allure.step('断言：分类文本等于详情页文本'):
            assert category_text in content_t

    @allure.step('在线小数据库-兽药残留-兽药查询')
    def veterinary_drugs_detail(self, veterinary_drugs_xpath, page_search_xpath, search_text, search_button,
                                results_xpath, content_text, index_page):
        with allure.step('点击数据查询模块'):
            self.base.sel_click((By.XPATH, veterinary_drugs_xpath))
        with allure.step('输入查询文本进行搜索'):
            self.base.input_box((By.XPATH, page_search_xpath), search_text)
            self.base.sel_click((By.XPATH, search_button))
            sleep(0.5)
        with allure.step('获取搜索结果列表'):
            drug_texts = self.base.get_text_list((By.XPATH, results_xpath))
        with allure.step('点击搜索结果列表的信息进入详情页'):
            self.base.sel_click((By.XPATH, results_xpath))
            self.base.switch_to_window()
        with allure.step('获取详情页文本'):
            drug_name = self.base.get_text((By.XPATH, content_text))
        with allure.step('关闭详情页返回首页'):
            self.base.close_window()
            self.base.switch_to_window()
            self.base.sel_click((By.XPATH, index_page))
        with allure.step('断言：搜索结果列表包含查询文本'):
            for drug_text in drug_texts:
                assert search_text in drug_text
            assert drug_name in drug_texts

    """小数据库-GB 29921预包装食品、GB 31607散装即食食品中致病菌限量"""

    # 部分模块调用营养强化剂方法
    @allure.step('在线小数据库-***-查询详情页')
    def zbj_search(self, zbj_xpath, page_search_xpath, search_text, search_button, result_xpath, index_page):
        with allure.step('点击致病菌查询'):
            self.base.sel_click((By.XPATH, zbj_xpath))
        with allure.step('输入查询文本点击搜索'):
            self.base.input_box((By.XPATH, page_search_xpath), search_text)
            self.base.sel_click((By.XPATH, search_button))
        with allure.step('获取搜索结果文本'):
            zbj_text = self.base.get_text((By.XPATH, result_xpath))
        with allure.step('点击返回首页'):
            self.base.sel_click((By.XPATH, index_page))
        with allure.step('断言：搜索结果文本等于查询文本'):
            assert search_text == zbj_text

    @allure.step('在线小数据库-***-系统查询')
    def db_index_search(self, search_select, select_xpath, search_input, search_text, search_button, results_xpath,
                        index_page):
        with allure.step('点击下拉选择搜索项'):
            self.base.sel_click((By.XPATH, search_select))
            self.base.sel_click((By.XPATH, select_xpath))
        with allure.step('输入搜索文本点击搜索'):
            self.base.input_box((By.XPATH, search_input), search_text)
            self.base.sel_click((By.XPATH, search_button))
        with allure.step('获取搜索结果文本列表'):
            word_list = self.base.get_text_list((By.XPATH, results_xpath))
        with allure.step('点击返回首页'):
            self.base.sel_click((By.XPATH, index_page))
        with allure.step('断言：搜索结果文本等于查询文本'):
            for word in word_list:
                assert word == search_text

    """小数据库-GB 2762-2017 食品中污染物限量|GB 2761-2017 食品中真菌毒素限量|GB 9685-2016 食品接触材料及制品用添加剂|GB 2760-2024 食品添加剂使用标准"""
    # 部分模块调用营养强化剂方法、致病菌数据库
    """小数据库-GB 2763-2021 食品中农药残留限量查询"""

    # 部分模块调用营养强化剂方法、致病菌数据库
    @allure.step('在线小数据库-农药残留-左侧分类')
    def ny_category(self, main_category, list_category, result_category, index_page):
        with allure.step('点击左侧分类'):
            self.base.sel_click((By.XPATH, main_category))
        with allure.step('获取文本列表'):
            text_list = self.base.get_text((By.XPATH, list_category))
        with allure.step('点击列表分类'):
            self.base.sel_click((By.XPATH, list_category))
        with allure.step('获取结果文本'):
            result_text = self.base.get_text((By.XPATH, result_category))
        with allure.step('点击返回首页'):
            self.base.sel_click((By.XPATH, index_page))
        with allure.step('断言：左侧分类等于结果文本'):
            assert text_list == result_text

    """小数据库-可用于食品的菌种名单查询"""

    @allure.step('在线小数据库-可用于食品的菌种名单查询-搜索')
    def strain_search(self, search_input, input_text, search_button, result_x, detail_x):
        with allure.step('输入框输入内容点击搜索'):
            self.base.switch_to_frame('mainiframe')
            self.base.input_box((By.XPATH, search_input), input_text)
            self.base.sel_click((By.XPATH, search_button))
        with allure.step('获取搜索结果文本'):
            result_text = self.base.get_text((By.XPATH, result_x))
        with allure.step('点击搜索结果进入详情页'):
            self.base.sel_click((By.XPATH, result_x))
        with allure.step('获取详情页文本'):
            detail_text = self.base.get_text((By.XPATH, detail_x))
        self.base.switch_to_default_content()
        with allure.step('断言：搜索结果文本等于详情页文本'):
            assert input_text == result_text and input_text == detail_text

    """小数据库-食品原料信息数据库"""

    @allure.step('在线小数据库-食品原料信息数据库-搜索')
    def food_material_search(self, search_select, selection, search_input, input_text, search_button, result_x,
                             detail_button, detail_x):
        with allure.step('选择下拉搜索项、输入框输入内容点击搜索'):
            self.base.switch_to_frame('mainiframe')
            self.base.sel_click((By.XPATH, search_select))
            self.base.sel_click((By.XPATH, selection))
            self.base.input_box((By.XPATH, search_input), input_text)
            self.base.sel_click((By.XPATH, search_button))
        with allure.step('获取搜索结果文本'):
            result_text = self.base.get_text((By.XPATH, result_x))
        with allure.step('点击搜索结果进入详情页'):
            self.base.sel_click((By.XPATH, detail_button))
        with allure.step('获取详情页文本'):
            detail_text = self.base.get_text((By.XPATH, detail_x))
        self.base.switch_to_default_content()
        with allure.step('断言：搜索结果文本等于详情页文本'):
            assert input_text in result_text and input_text in detail_text

    @allure.step('在线小数据库-食品原料信息数据库-搜索')
    def food_material_search2(self, search_select, selection, search_input, input_text, search_button, result_x,
                             detail_button, detail_x):
        with allure.step('选择下拉搜索项、输入框输入内容点击搜索'):
            self.base.sel_click((By.XPATH, search_select))
            self.base.sel_click((By.XPATH, selection))
            self.base.input_box((By.XPATH, search_input), input_text)
            self.base.sel_click((By.XPATH, search_button))
        with allure.step('获取搜索结果文本'):
            result_text = self.base.get_text((By.XPATH, result_x))
        with allure.step('点击搜索结果进入详情页'):
            self.base.sel_click((By.XPATH, detail_button))
        with allure.step('获取详情页文本'):
            detail_text = self.base.get_text((By.XPATH, detail_x))
        with allure.step('断言：搜索结果文本等于详情页文本'):
            assert input_text in result_text and input_text in detail_text

    @allure.step('在线小数据库-食品原料信息数据库-搜索')
    def food_material_search2(self, search_select, selection, search_input, input_text, search_button, result_x,
                              detail_button, detail_x):
        # 搜索
        with allure.step('点击下拉搜索项、输入框输入内容点击搜索'):
            self.base.sel_click((By.XPATH, search_select))
            self.base.sel_click((By.XPATH, selection))
            self.base.input_box((By.XPATH, search_input), input_text)
            self.base.sel_click((By.XPATH, search_button))
        with allure.step('获取搜索结果文本'):
            result_text = self.base.get_text((By.XPATH, result_x))
        with allure.step('点击搜索结果进入详情页'):
            self.base.sel_click((By.XPATH, detail_button))
        with allure.step('获取详情页文本'):
            detail_text = self.base.get_text((By.XPATH, detail_x))
        with allure.step('断言：搜索结果文本等于详情页文本'):
            assert input_text in result_text and input_text in detail_text

    """小数据库-食品生产许可审查细则查询数据库"""

    @allure.step('在线小数据库-食品生产许可审查细则查询数据库-类别')
    def permit_category(self, food_cate, right_cate, search_xpath, search_text, search_button, result_xpath):
        with allure.step('获取左侧类别文本'):
            left_text = self.base.get_text((By.XPATH, food_cate))
        with allure.step('点击左侧类别模块'):
            self.base.sel_click((By.XPATH, food_cate))
        with allure.step('获取右侧类别文本'):
            right_texts = self.base.get_text_list((By.XPATH, right_cate))
        with allure.step('输入内容搜索'):
            self.base.input_box((By.XPATH, search_xpath), search_text)
            self.base.sel_click((By.XPATH, search_button))
        with allure.step('获取搜索结果文本'):
            result_text = self.base.get_text((By.XPATH, result_xpath), mode=1)
        with allure.step('还原'):
            self.base.input_box((By.XPATH, search_xpath), '')
            self.base.sel_click((By.XPATH, search_button))
        with allure.step('断言：验证类别'):
            for right_text in right_texts:
                assert right_text == left_text
        with allure.step('断言：验证搜索结果'):
            assert search_text in result_text

    @allure.story('在线小数据库-食品生产许可审查细则查询数据库-地区')
    def permit_area(self, m_area, area_city, area_list_path, m_cate):
        with allure.step('点击地区模块'):
            self.base.sel_click((By.XPATH, m_area))
        with allure.step('获取城市文本'):
            city_text = self.base.get_text((By.XPATH, area_city))
        with allure.step('点击地区筛选项'):
            self.base.sel_click((By.XPATH, area_city))
        with allure.step('获取城市列表'):
            city_list = self.base.get_text_list((By.XPATH, area_list_path))
        with allure.step('点击返回'):
            self.base.sel_click((By.XPATH, m_cate))
        with allure.step('断言：验证地区名称'):
            for city in city_list:
                assert city == city_text

    """小数据库-化妆品原料查询数据库"""

    @allure.step('在线小数据库-化妆品原料查询数据库-搜索查看详情')
    def cosmetics_search_content(self, search_input, input_text, search_button, result_x, detail_button, detail_x,
                                 index_path):
        with allure.step('输入搜索内容'):
            self.base.input_box((By.XPATH, search_input), input_text)
        with allure.step('点击搜索按钮'):
            self.base.sel_click((By.XPATH, search_button))
        with allure.step('获取搜索结果'):
            result_text = self.base.get_text((By.XPATH, result_x))
        with allure.step('点击搜索结果进入详情'):
            self.base.sel_click((By.XPATH, detail_button))
        with allure.step('获取详情页内容'):
            detail_text = self.base.get_text((By.XPATH, detail_x))
        with allure.step('返回首页'):
            self.base.sel_click((By.XPATH, index_path))
        with allure.step('断言：验证搜索结果和详情页内容'):
            assert input_text in result_text and input_text in detail_text

    @allure.step('在线小数据库-化妆品原料查询数据库-子模块')
    def cosmetics_cf(self, m_name, click_path, list_title, list_name, detail_button, detail_path, index_path):
        # 模块列表和详情
        with allure.step('点击进入子模块页面'):
            self.base.sel_click((By.XPATH, click_path))
            sleep(0.5)
        with allure.step('获取标题和列表内容'):
            list_t = self.base.get_text((By.XPATH, list_title))
            list_n = self.base.get_text((By.XPATH, list_name))
        with allure.step('点击进入详情页'):
            self.base.sel_click((By.XPATH, detail_button))
            sleep(1)
        with allure.step('获取详情页内容'):
            detail_text = self.base.get_text((By.XPATH, detail_path))
        with allure.step('返回首页'):
            self.base.sel_click((By.XPATH, index_path))
        with allure.step('断言：验证模块标题和列表、内容页'):
            assert m_name == list_t
            assert list_n == detail_text

    """小数据库-营养功能成分数据库"""

    @allure.step('在线小数据库-营养功能-搜索')
    def nutr_fction_search(self, search_select, selection, search_input, input_text, search_button, result_x,
                           detail_button, detail_x):
        # 搜索
        self.base.switch_to_frame(0)
        with allure.step('点击选择搜索项'):
            self.base.sel_click((By.XPATH, search_select))
            self.base.sel_click((By.XPATH, selection))
        with allure.step('输入搜索内容'):
            self.base.input_box((By.XPATH, search_input), input_text)
        with allure.step('点击搜索按钮'):
            self.base.sel_click((By.XPATH, search_button))
        with allure.step('获取搜索结果'):
            result_text = self.base.get_text((By.XPATH, result_x))
        with allure.step('点击详情按钮'):
            self.base.sel_click((By.XPATH, detail_button))
        with allure.step('获取详情页的内容'):
            detail_text = self.base.get_text((By.XPATH, detail_x))
        self.base.switch_to_default_content()
        with allure.step('验证搜索结果和详情页内容'):
            assert input_text in result_text and input_text in detail_text

    """小数据库-保健食品相关信息查询数据库"""

    @allure.step('保健食品-子数据库')
    def health_care_db(self, sub_db_into, target, sub_text, sub_db_name, db_mode):
        with allure.step('点击访问子数据库'):
            self.base.sel_click((By.XPATH, sub_db_into))
        with allure.step('获取子数据库文本'):
            result_text = ''
            if target == 'none':
                result_text = self.base.get_text((By.XPATH, sub_text))
            elif target == '_blank':
                self.base.switch_to_window()
                result_text = self.base.get_text((By.XPATH, sub_text))
                self.base.close_window()
                self.base.switch_to_window()
        with allure.step('返回保健食品数据库页面'):
            self.base.sel_click((By.XPATH, db_mode))
        with allure.step('验证子数据库文本'):
            assert sub_db_name in result_text

    """小数据库-全文索引系统"""

    @allure.step('输入框搜索')
    def qw_bf_search(self, search_input, input_text, search_button, result_xpath):
        """输入框搜索，结果验证"""
        with allure.step('输入框搜索'):
            self.base.input_box((By.XPATH, search_input), input_text)
            self.base.sel_click((By.XPATH, search_button))
        with allure.step('获取搜索结果'):
            result_text = self.base.get_text((By.XPATH, result_xpath), mode=1)
        with allure.step('验证搜索结果'):
            assert input_text in result_text

    """小数据库-国家食品安全监督抽检查询系统"""

    @allure.step('国家食品安全监督抽检查询系统-抽检项目查询左侧分类')
    def check_category(self, list_category, result_category, index_page):
        # 切换分类
        with allure.step('获取左侧分类列表的分类名称'):
            text_list = self.base.get_text((By.XPATH, list_category))
        with allure.step('获取分类列表的分类'):
            self.base.sel_click((By.XPATH, list_category))
        with allure.step('获取右侧的分类名称'):
            result_text = self.base.get_text((By.XPATH, result_category))
        with allure.step('点击返回首页'):
            self.base.sel_click((By.XPATH, index_page))
        with allure.step('验证分类名'):
            assert text_list == result_text

    @allure.step('国家食品安全监督抽检查询系统-抽检项目查询分类详情页')
    def check_category_content(self, category_xpath, page_category, content_text, index_page):
        with allure.step('点击分类'):
            self.base.sel_click((By.XPATH, category_xpath))
        with allure.step('获取分类列表的分类名称'):
            category_text = self.base.get_text((By.XPATH, page_category))
        with allure.step('点击分类'):
            self.base.sel_click((By.XPATH, page_category))
        with allure.step('获取详情页分类名'):
            content_t = self.base.get_text((By.XPATH, content_text))
        with allure.step('点击返回模块首页'):
            self.base.sel_click((By.XPATH, index_page))
        with allure.step('验证分类名'):
            assert category_text in content_t

    @allure.step('国家食品安全监督抽检项目查询-查询详情页')
    def check_detail(self, cate_xpath, page_search_xpath, search_text, search_button, result_xpath, index_page):
        with allure.step('点击进入项目查询模块'):
            self.base.sel_click((By.XPATH, cate_xpath))
        with allure.step('输入查询内容'):
            self.base.input_box((By.XPATH, page_search_xpath), search_text)
        with allure.step('点击搜索按钮'):
            self.base.sel_click((By.XPATH, search_button))
        with allure.step('获取搜索结果'):
            text = self.base.get_text((By.XPATH, result_xpath))
        with allure.step('点击返回模块首页'):
            self.base.sel_click((By.XPATH, index_page))
        with allure.step('验证搜索结果'):
            assert search_text == text

    @allure.step('抽检项目查询-系统查询')
    def index_search(self, search_select, select_xpath, search_input, search_text, search_button, results_xpath):
        # 搜索模块
        with allure.step('选择搜索类型'):
            self.base.sel_click((By.XPATH, search_select))
            self.base.sel_click((By.XPATH, select_xpath))
        with allure.step('输入搜索内容'):
            self.base.input_box((By.XPATH, search_input), search_text)
        with allure.step('点击搜索按钮'):
            self.base.sel_click((By.XPATH, search_button))
        with allure.step('获取搜索结果列表'):
            word_list = self.base.get_text_list((By.XPATH, results_xpath))
        with allure.step('遍历验证搜索结果'):
            for word in word_list:
                assert word == search_text

    """小数据库-濒危野生动植物名录查询数据库"""

    @allure.step('濒危野生动植物名录查询数据库-首页、濒危野生动植物种国际贸易公约')
    def bw_index_cites(self, cites_xpath, index_text, cites_text):
        # 验证首页
        with allure.step('获取页面内容'):
            text_index = self.base.get_text((By.XPATH, index_text))
            text_index = re.sub('[^\u4e00-\u9fa5]+', '', text_index)
        # 验证CITES页
        with allure.step('点击濒危野生动植物种国际贸易公约CITES页'):
            self.base.sel_click((By.XPATH, cites_xpath))
        with allure.step('获取濒危野生动植物种国际贸易公约页面内容'):
            text_cites = self.base.get_text((By.XPATH, cites_text))
            text_cites = re.sub('[^\u4e00-\u9fa5]+', '', text_cites)
        with allure.step('验证首页和濒危野生动植物种国际贸易公约页面内容'):
            assert text_index == "濒危野生动植物名录查询数据库介绍"
            assert text_cites == "濒危野生动植物种国际贸易公约"

    @allure.step('国家重点保护野生动植物')
    def bw_more_help(self, catalog_xpath, title_xpath, title_text):
        # 验证
        with allure.step('点击分类'):
            self.base.sel_click((By.XPATH, catalog_xpath))
        with allure.step('获取页面内容'):
            text = self.base.get_text((By.XPATH, title_xpath))
            text = re.sub('[^\u4e00-\u9fa5]+', '', text)
        with allure.step('验证页面内容'):
            assert text == title_text

    @allure.step('濒危野生动植物搜索')
    def bw_endangered_search(self, input_xpath, input_text, all_search_button, result_db_xpath, db_content):
        # 搜索
        with allure.step('输入搜索内容'):
            self.base.input_box((By.XPATH, input_xpath), input_text)
        with allure.step('点击搜索按钮'):
            self.base.sel_click((By.XPATH, all_search_button))
        with allure.step('点击结果列表项目，进入详情页'):
            self.base.sel_click((By.XPATH, result_db_xpath))
        with allure.step('获取详情页内容'):
            text = self.base.get_text((By.XPATH, db_content), mode=1)
            text = re.sub('[^\u4e00-\u9fa5]+', '', text)
        with allure.step('验证搜索结果'):
            assert input_text in text

    @allure.step('获取标签中href值')
    def check_href(self, href_xpath):
        try:
            href = self.base.get_href((By.XPATH, href_xpath))
            return href
        except:
            return None

    @allure.step('验证分类-href方法')
    def check_category_href(self, category_url_xpath, category_text_xpath, result_xpath, module_xpath):
        with allure.step('获取分类url'):
            category_urls = self.base.get_href_list((By.XPATH, category_url_xpath))
        with allure.step('获取分类文本'):
            category_texts = self.base.get_text_list((By.XPATH, category_text_xpath))
        with allure.step('遍历列表url'):
            i = 0
            for category_url in category_urls:
                if category_url is not None:
                    with allure.step('获取列表当前项的文本'):
                        category_text = category_texts[i]
                    with allure.step('进入模块列表页'):
                        self.base.open_new_tab(category_url)
                        sleep(0.2)
                        self.base.switch_to_window()
                    with allure.step('获取模块列表页文本信息'):
                        result_text = self.base.get_text((By.XPATH, result_xpath)).strip()
                    with allure.step('页面还原'):
                        self.base.close_window()
                        self.base.switch_to_window()
                        self.base.sel_click((By.XPATH, module_xpath))
                        sleep(0.5)
                    with allure.step('验证列表项文本是否在详情页'):
                        assert category_text[3:] in result_text or category_text[2:6] in result_text
                i += 1

    @allure.step('验证信息详情页')
    def check_content_title(self, list_title_locator, list_url_locator, content_title_locator, reset_button):
        with allure.step('获取列表页标题'):
            list_title = self.base.get_text((By.XPATH, list_title_locator))
            if list_title:
                list_title = list_title.strip()
        with allure.step('点击进入详情页'):
            is_blank = self.base.get_target((By.XPATH, list_url_locator))
            self.base.sel_click((By.XPATH, list_url_locator))
            sleep(0.2)
            if is_blank:
                self.base.switch_to_window()
        with allure.step('获取详情页目标内容'):
            content_title = self.base.get_text((By.XPATH, content_title_locator))
            if content_title:
                content_title = content_title.strip()
        with allure.step('返回模块首页'):
            if is_blank:
                self.base.close_window()
                self.base.switch_to_window()
            else:
                self.base.sel_click((By.XPATH, reset_button))
                sleep(0.2)
        with allure.step('验证列表标题包含详情页标题信息'):
            assert content_title is not None
            assert list_title is not None
            assert content_title in list_title or list_title in content_title

    @allure.step('输入框搜索，列表验证、+详情页验证关键词')
    def input_search_content_check(self, src_input_locator, input_text, search_button, src_list, src_url_list,
                                   reset_button, content_locator, no_data_locator):
        """输入框搜索，列表、详情页验证关键词"""
        with allure.step('获取原始的列表数据'):
            text_original_list = self.base.get_text_list((By.XPATH, src_list))
        with allure.step('输入框输入搜索关键词'):
            self.base.input_box((By.XPATH, src_input_locator), input_text)
            sleep(1)
        with allure.step('点击搜索按钮'):
            self.base.sel_click((By.XPATH, search_button))
            sleep(2)
        with allure.step('获取搜索后的列表数据，验证等待列表加载'):
            text_list = self.base.get_text_list((By.XPATH, src_list))
            wi = 0
            while wi < 10:
                if text_list == text_original_list:
                    wi += 1
                    sleep(5)
                    text_list = self.base.get_text_list((By.XPATH, src_list))
                else:
                    break
        no_data = self.base.is_element_exist((By.XPATH, no_data_locator))
        if no_data is True:
            with allure.step('如果列表验证失败，获取搜索后的列表url'):
                for text in text_list:
                    if input_text not in text:
                        url_list = self.base.get_href_list((By.XPATH, src_url_list))
                        break
            i = 0
            for text in text_list:
                if input_text not in text:
                    with allure.step('搜索结果列表中，没有包含搜索关键词，打开详情页'):
                        self.base.open_new_tab(url_list[i])
                        self.base.switch_to_window()
                        sleep(0.2)
                    with allure.step('详情页获取内容'):
                        content_text = self.base.get_text((By.XPATH, content_locator))
                        content_text = re.sub(r"\s", "", content_text)
                    with allure.step('关闭详情页'):
                        self.base.close_window()
                        self.base.switch_to_window()
                    with allure.step('断言：验证详情页内容包含搜索关键词'):
                        assert input_text in content_text
                i += 1
        with allure.step('点击返回模块首页'):
            self.base.sel_click((By.XPATH, reset_button))

    @allure.step('下拉选择搜索，列表验证、+详情页验证关键词')
    def select_search_content_check(self, selected_text_locator, select_box_locator, select_item_value, search_button,
                                    src_list, src_url_list, reset_button, content_locator, no_data_locator):
        """下拉选择搜索，列表、详情页验证关键词"""
        with allure.step('获取原始的列表数据'):
            text_original_list = self.base.get_text_list((By.XPATH, src_list))
        with allure.step('获取搜索选项文本'):
            selected_text = self.base.get_text((By.XPATH, selected_text_locator))
        with allure.step('选择搜索选项'):
            self.base.select_box((By.XPATH, select_box_locator), select_item_value)
            sleep(1)
        with allure.step('点击搜索按钮'):
            self.base.sel_click((By.XPATH, search_button))
            sleep(2)
        with allure.step('获取搜索后的列表数据，验证等待列表加载'):
            text_list = self.base.get_text_list((By.XPATH, src_list))
            wi = 0
            while wi < 10:
                if text_list == text_original_list:
                    wi += 1
                    sleep(5)
                    text_list = self.base.get_text_list((By.XPATH, src_list))
                else:
                    break
        no_data = self.base.is_element_exist((By.XPATH, no_data_locator))
        if no_data is True:
            with allure.step('如果列表验证失败，获取搜索后的列表url'):
                for text in text_list:
                    if selected_text not in text:
                        url_list = self.base.get_href_list((By.XPATH, src_url_list))
                        break
            i = 0
            for text in text_list:
                if selected_text not in text:
                    with allure.step('搜索结果列表中，没有包含搜索关键词，打开详情页'):
                        self.base.open_new_tab(url_list[i])
                        self.base.switch_to_window()
                        sleep(0.2)
                    with allure.step('详情页获取内容'):
                        content_text = self.base.get_text((By.XPATH, content_locator))
                        content_text = re.sub(r"\s", "", content_text)
                    with allure.step('关闭详情页'):
                        self.base.close_window()
                        self.base.switch_to_window()
                    with allure.step('断言：验证详情页内容包含搜索关键词'):
                        assert selected_text in content_text
                i += 1
        with allure.step('点击返回模块首页'):
            self.base.sel_click((By.XPATH, reset_button))

    @allure.step('点击下拉，点击选择搜索，列表验证、+详情页验证关键词')
    def select_click_search_content_check(self, selected_text_locator, select_box_locator, select_item_locator,
                                          search_button, src_list, src_url_list, reset_button, content_locator,
                                          no_data_locator):
        """点击下拉点击选择搜索，列表、详情页验证关键词"""
        with allure.step('获取原始的列表数据'):
            text_original_list = self.base.get_text_list((By.XPATH, src_list))
        with allure.step('点击下拉选择框'):
            self.base.sel_click((By.XPATH, select_box_locator))
        with allure.step('获取搜索选项文本'):
            selected_text = self.base.get_text((By.XPATH, selected_text_locator))
        with allure.step('选择搜索选项'):
            self.base.sel_click((By.XPATH, select_item_locator))
            sleep(1)
        with allure.step('点击收回下拉选择框'):
            select_visible = self.base.is_select_visible((By.XPATH, selected_text_locator))
            if select_visible is True:
                self.base.sel_click((By.XPATH, select_box_locator))
        with allure.step('点击搜索按钮'):
            self.base.sel_click((By.XPATH, search_button))
            sleep(2)
        with allure.step('获取搜索后的列表数据，验证等待列表加载'):
            text_list = self.base.get_text_list((By.XPATH, src_list))
            wi = 0
            while wi < 10:
                if text_list == text_original_list:
                    wi += 1
                    sleep(5)
                    text_list = self.base.get_text_list((By.XPATH, src_list))
                else:
                    break
        no_data = self.base.is_element_exist((By.XPATH, no_data_locator))
        if no_data is True:
            with allure.step('如果列表验证失败，获取搜索后的列表url'):
                for text in text_list:
                    if selected_text not in text:
                        url_list = self.base.get_href_list((By.XPATH, src_url_list))
                        break
            i = 0
            for text in text_list:
                if selected_text not in text:
                    with allure.step('搜索结果列表中，没有包含搜索关键词，打开详情页'):
                        self.base.open_new_tab(url_list[i])
                        self.base.switch_to_window()
                        sleep(0.2)
                    with allure.step('详情页获取内容'):
                        content_text = self.base.get_text((By.XPATH, content_locator))
                        content_text = re.sub(r"\s", "", content_text)
                    with allure.step('关闭详情页'):
                        self.base.close_window()
                        self.base.switch_to_window()
                    with allure.step('断言：验证详情页内容包含搜索关键词'):
                        print(selected_text, "\n", content_text)
                        assert selected_text in content_text
                i += 1
        with allure.step('点击返回模块首页'):
            self.base.sel_click((By.XPATH, reset_button))

    @allure.step('验证页面404 Not Found')
    def check_404(self):
        with allure.step('获取当前页面文本'):
            text = self.base.get_text((By.XPATH, '//body/center[1]/h1'))
        if text == '404 Not Found':
            log.error('页面返回404 Not Found')
            self.close_module()
        else:
            return "200 OK"

    @allure.step('列表显示无数据')
    def check_no_data(self, no_data_locator):
        with allure.step('获取列表“无数据”字段'):
            no_data = self.base.is_element_exist((By.XPATH, no_data_locator))
        if no_data is True:
            log.info('列表有数据')
            return True
        else:
            log.info('列表无数据')
            return False

    @allure.step('切入iframe')
    def switch_to_iframe(self, iframe_id):
        with allure.step('切入iframe'):
            self.base.switch_to_frame(iframe_id)

    @allure.step('切出iframe')
    def switch_to_default_content(self):
        with allure.step('切出iframe'):
            self.base.switch_to_default_content()
